// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        wheelNode: cc.Node,
        itemNum: 8,
        tipbarLayer: cc.Node,
        tipLable: cc.Label
    },

    getRandom: function(e, t) {
        return Math.floor(Math.random(0, .99) * (t - e)) + e
    },
    onStartWheel: function() {
        let self = this
        self.wheelNode.angle = 0
        let target = self.getRandom(0, 360)
        console.log('target:' + target)
        cc.tween(self.wheelNode)
        .by(2, { angle: -2160 }, { easing: 'quartIn' }) 
        .by(3, { angle: -(target + 1080)}, { easing: 'quartOut' })
        .call(() => { self.getReward(target) })
        .start()
    },
    getReward: function(target) {
        let self = this
        switch (Math.floor(target / (360 / self.itemNum))) {
            case 0:
                self.tipLable.string = '恭喜你抽中100积分！'
                break
            case 1:
                self.tipLable.string = '恭喜你抽中50积分！'
                break
            case 2:
                self.tipLable.string = '恭喜你抽中80积分！'
                break
            case 3:
                self.tipLable.string = '恭喜你抽中20积分！'
                break
            case 4:
                self.tipLable.string = '恭喜你抽中100积分！'
                break
            case 5:
                self.tipLable.string = '恭喜你抽中50积分！'
                break
            case 6:
                self.tipLable.string = '恭喜你抽中80积分！'
                break
            case 7:
                self.tipLable.string = '恭喜你抽中20积分！'
        }
        self.tipbarLayer.active = true
        cc.tween(self.tipbarLayer)
        .delay(2)
        .call(() => { 
            self.tipbarLayer.active = false
        })
        .start()
    }
});
